package com.sixbro.shiro.session.common;

import lombok.Data;

import java.util.HashMap;

/**
 * <p>
 * API接口的基础返回类
 * </p>
 *
 * @Author: Mr.Lu
 * @Since: 2020/6/17 15:24
 */
@Data
public class BaseResponse extends HashMap<String, Object> {
    private static final long serialVersionUID = -8713837118340960775L;

    // 成功
    private static final Integer SUCCESS = 0;
    // 警告
    private static final Integer WARN = 1;
    // 异常 失败
    private static final Integer FAIL = 500;


    private String code;

    private String msg;

    private Object result;

    public BaseResponse() {
        put("code", SUCCESS);
        put("msg", "操作成功");
    }

    public BaseResponse(String code, String msg, Object result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public static BaseResponse error() {
        return BaseResponse.error("");
    }

    public static BaseResponse error(Object msg) {
        BaseResponse ResponseBo = new BaseResponse();
        ResponseBo.put("code", FAIL);
        ResponseBo.put("msg", msg);
        return ResponseBo;
    }

    public static BaseResponse ok() {
        return new BaseResponse();
    }

    public static BaseResponse ok(Object msg) {
        BaseResponse ResponseBo = new BaseResponse();
        ResponseBo.put("code", SUCCESS);
        ResponseBo.put("msg", msg);
        return ResponseBo;
    }

    public static BaseResponse warn(Object msg) {
        BaseResponse ResponseBo = new BaseResponse();
        ResponseBo.put("code", WARN);
        ResponseBo.put("msg", msg);
        return ResponseBo;
    }

    @Override
    public BaseResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
